<template>
  <div class="login-container">
    <el-row type="flex" justify="center" :gutter="20">
      <el-col :xs="22" :sm="12" :md="22" :lg="8" :xl="6">
        <div class="login-form">
          <div class="title-container">
            <h3 class="title">{{ sitaName }}-找回密码</h3>
          </div>
          <forget />
          <el-row :gutter="20" class="padding-lr-sm">
            <el-col :span="12" :offset="0">
              <el-button
                type="text"
                class="text-white"
                @click.native.prevent="handleLogin"
                >已有账户</el-button
              >
            </el-col>
            <el-col :span="12" :offset="0" class="text-right">
              <el-button
                type="text"
                class="text-white"
                @click.native.prevent="handleForget"
                >忘记密码</el-button
              >
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>

    <el-dialog
      :close-on-click-modal="false"
      title="Or connect with"
      :visible.sync="showDialog"
    >
      Can not be simulated on local, so please combine you own business
      simulation! ! !
      <br />
      <br />
      <br />
      <social-sign />
    </el-dialog>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate";
import SocialSign from "./components/SocialSignin";
import Forget from "./components/Forget";
import {config} from '@/utils/publicUtil'

import { getView } from "diandi-admin/lib/api/addons/store.js";

export default {
  components: {
    SocialSign,
    Forget
  },
  data() {
    return {
      loginFormType: "AccountLogin",
      sitaName: config.siteName,
      showDialog: false,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        const query = route.query;
        if (query) {
          this.redirect = query.redirect;
          this.otherQuery = this.getOtherQuery(query);
        }
      },
      immediate: true,
    },
  },
  created() {
    // window.addEventListener('storage', this.afterQRScan)
  },
  destroyed() {
    // window.removeEventListener('storage', this.afterQRScan)
  },
  methods: {
    checkCapslock(e) {
      const { key } = e;
      this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
    },
    handleLogin(){
      this.$router.push({path:'/login'})
    },
    handleTypeClick(tab, event) {
      if(this.loginFormType === 'AccountLogin'){
          
      }
      console.log(tab, event,this.loginFormType);
    },
    handleRegister() {
      this.$router.push({path:'/register'})
    },
    handleForget() {
      this.$router.push({path:'/forget'})
    },
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== "redirect") {
          acc[cur] = query[cur];
        }
        return acc;
      }, {});
    },
    initStoreList: function (data) {
      const that = this;
      console.log("登录成功initStoreList");
      this.$store.dispatch("permission/setMenuType", data.module_name);
      if (data.store_id) {
        getView(data.store_id).then((res) => {
          that.$store.dispatch("app/setBlocs", res.data);
          that.$store.dispatch("elForm/changeSetting", {
            key: "attachmentUrl",
            value: res.data.config.attachmentUrl,
          });
        });
      }
    },
    // afterQRScan() {
    //   if (e.key === 'x-admin-oauth-code') {
    //     const code = getQueryObject(e.newValue)
    //     const codeMap = {
    //       wechat: 'code',
    //       tencent: 'code'
    //     }
    //     const type = codeMap[this.auth_type]
    //     const codeName = code[type]
    //     if (codeName) {
    //       this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
    //         this.$router.push({ path: this.redirect || '/' })
    //       })
    //     } else {
    //       alert('第三方登录失败')
    //     }
    //   }
    // }
  },
};
</script>
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #1474caa8;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  span.svg-container {
    font-size: 16px;
    padding: 15px;
    background: #e5e5e5;
    border-radius: 4px 0px 0px 4px;
  }
  .el-input {
    height: 48px;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
::v-deep .el-tabs__nav {
  .el-tabs__item {
    font-weight: 600;
    font-size: 16px;
    color: #5c9edb;
    &:hover {
      color: #fff;
    }
  }
  .is-active {
    color: #fff;
  }
}

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;
  background: url("~@/static/common/login_background.png");
  background-size: cover;

  .login-form {
    width: calc(100% - 40px);
    // height: 380px;
    padding: 4vh;
    margin-top: calc(40vh - 190px);
    margin-right: 20px;
    margin-left: 20px;
    background: url("~@/static/common/login_form.png");
    background-size: 100% 100%;
    border-radius: 10px;
    box-shadow: 0 2px 8px 0 rgb(7 17 27 / 6%);
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>